package com.fake.handwriting.fake_handwriting
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import androidx.core.content.FileProvider
import java.io.File

class Util {
    companion object{
        fun shareFile(mContext:Context,fileName: String) {
            val file = File(fileName)
            if (file.exists()) {
                val intent = Intent(Intent.ACTION_SEND)
                intent.type = "application/*"
                intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    val contentUri = FileProvider.getUriForFile(
                        mContext,
                        BuildConfig.APPLICATION_ID + ".fileprovider",
                        file
                    )
                    intent.putExtra(Intent.EXTRA_STREAM, contentUri)
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                } else {
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
                }
                mContext.startActivity(Intent.createChooser(intent, "share to"))
            }
        }
    }
}